home *** CD-ROM | disk | FTP | other *** search
- #TRUSTED 011297d42dd1f9e458f7ddb9d3117a52e0149a2355c0d4e8e05f8040d98e8df1fb30f7b8f98b503a1f239d6aa826c67e3cb4205f3a4ae7bb52bd0dabbdd408dc4c417ad84674ec0a279f33f2e1d68e12461bef50fae5b2b9e8074ac8ff0a071d79be783c62349dd13ee7a2a6d369d5fcd3e5c53aa1db34483b96c6b5e865b513f765d22b7cab63a90b006d6037abc751334f5c755219e873a04c41b9df221c05dbe10882eb5829f581d737c2a896b03dd2092987137509cd5d28692a93c464b5cdb585a647f24e96afb96e56eca6e197ba6d3d46f02903f959b1b7cf04304c9400d02dd370078f0042a3470a14e5382bd15c49ee24a1e7725a710277fe375c14e1478ea5737efccb2d9551361e001860977d6759b65fb2285610ce4f8e204b52e6e3f3ea9e14790ad9d4dfafe2bc66bcc211bf095cb0ed9fdd8160124c39c0fb6de97173302e5d64db9b3751f994c7e27620537132ed027e91931ea55531572f2b06d540ff896a2d0351feebe23ac2c9bf6107252bde27dda4cb6ab43f2826757e8d9cd95bf3ba03dc794c17049dd65cefde19a6e1e244fb7aa42de914e4e9dfbc3bca93f76dba4d922e39c3679d669c31016d5e50e3b08d53e14be053ccfb945200b5123135f6fd3654563c0243d91e5a136bf43731a59469db2817fc835d31d3f5354b6e289608064381dbf54559c094ee4ca35ea914a428910b9240b552f5
- #
- # This script was written by Michel Arboi <arboi@alussinan.org>
- #
- # GPL
- #
- if ( ! defined_func("pread") || ! defined_func("fread") ||
- ! defined_func("get_preference") ) exit(0);
- if ( ! find_in_path("amap") ) exit(0);
-
-
- if(description)
- {
- script_id(14663);
- script_version ("1.10");
- name["english"] = "amap (NASL wrapper)";
- script_name(english:name["english"]);
-
- desc["english"] = "
- This plugin runs amap to find open ports and identify applications.
- See the section 'plugins options' to configure it
-
- ";
-
- script_description(english:desc["english"]);
-
- summary["english"] = "Performs portscan / RPC scan / application recognition";
- script_summary(english:summary["english"]);
-
- script_category(ACT_SCANNER);
-
- script_copyright(english:"This script is Copyright (C) 2004 Michel Arboi");
- family["english"] = "Port scanners";
- family["francais"] = "Scanners de ports";
- script_family(english:family["english"], francais:family["francais"]);
-
- script_dependencies("ping_host.nasl");
-
- if (NASL_LEVEL < 2181) exit(0); # Cannot run
-
- script_add_preference(name: "File containing machine readable results : ", value: "", type: "file");
-
- script_add_preference(name:"Mode", type:"radio", value: "Map applications;Just grab banners;Port scan only");
- script_add_preference(name:"Quicker", type:"checkbox", value: "no");
- script_add_preference(name:"UDP scan (disabled in safe_checks)", type:"checkbox", value: "no");
- script_add_preference(name:"SSL (disabled in safe_checks)", type:"checkbox", value: "yes");
- script_add_preference(name:"RPC (disabled in safe_checks)", type:"checkbox", value: "yes");
-
- script_add_preference(name:"Parallel tasks", type:"entry", value: "");
- script_add_preference(name:"Connection retries", type:"entry", value: "");
- script_add_preference(name:"Connection timeout", type:"entry", value: "");
- script_add_preference(name:"Read timeout", type:"entry", value: "");
-
- exit(0);
- }
-
- #
- function hex2raw(s)
- {
- local_var i, j, ret, l;
-
- s = chomp(s); # remove trailing blanks, CR, LF...
- l = strlen(s);
- if (l % 2) display("hex2raw: odd string: ", s, "\n");
- for(i=0;i<l;i+=2)
- {
- if(ord(s[i]) >= ord("0") && ord(s[i]) <= ord("9"))
- j = int(s[i]);
- else
- j = int((ord(s[i]) - ord("a")) + 10);
-
- j *= 16;
- if(ord(s[i+1]) >= ord("0") && ord(s[i+1]) <= ord("9"))
- j += int(s[i+1]);
- else
- j += int((ord(s[i+1]) - ord("a")) + 10);
- ret += raw_string(j);
- }
- return ret;
- }
-
- if (NASL_LEVEL < 2181 || ! defined_func("pread") || ! defined_func("get_preference"))
- {
- set_kb_item(name: "/tmp/UnableToRun/14663", value: TRUE);
- display("Script #14663 (amap_wrapper) cannot run - upgrade libnasl\n");
- exit(0);
- }
-
- function on_exit()
- {
- if (tmpnam) unlink(tmpnam);
- }
-
- __gs_opt = get_kb_item("global_settings/experimental_scripts");
- if (! COMMAND_LINE && "yes" >!< __gs_opt)
- {
- display('amap.nasl is an "experimental script". Disabled\n');
- exit(0);
- }
-
-
- ip = get_host_ip();
- esc_ip = ""; l = strlen(ip);
- for (i = 0; i < l; i ++)
- if (ip[i] == '.')
- esc_ip = strcat(esc_ip, "\.");
- else
- esc_ip = strcat(esc_ip, ip[i]);
-
- res = script_get_preference_file_content("File containing machine readable results : ");
- if (res)
- res = egrep(pattern: "^" + esc_ip + ":[0-9]+:", string: res);
- if (! res)
- {
- # No result, launch amap
- tmpdir = get_tmp_dir();
- if ( ! tmpdir ) exit(0);
- tmpnam = strcat(tmpdir, "amap-", get_host_ip(), "-", rand());
-
- p = script_get_preference("UDP scan");
- if ("yes" >< p)
- udp_n = 1;
- else
- udp_n = 0;
-
- n_ports = 0;
-
- for (udp_flag = 0; udp_flag <= udp_n; udp_flag ++)
- {
- i = 0;
- argv[i++] = "amap";
- argv[i++] = "-q";
- argv[i++] = "-U";
- argv[i++] = "-o";
- argv[i++] = tmpnam;
- argv[i++] = "-m";
- if (udp_flag) argv[i++] = "-u";
-
- p = script_get_preference("Mode");
- if ("Just grab banners" >< p) argv[i++] = '-B';
- else if ("Port scan only" >< p) argv[i++] = '-P';
- else argv[i++] = '-A';
-
- # As all UDP probes are declared harmful, -u is incompatible with -H
- # Amap exits immediatly with a strange error.
- # I let it run just in case some "harmless" probes are added in a
- # future version
-
- if (safe_checks()) argv[i++] = "-H";
-
- p = script_get_preference("Quicker");
- if ("yes" >< p) argv[i++] = "-1";
-
- # SSL and RPC probes are "harmful" and will not run if -H is set
-
- p = script_get_preference("SSL");
- if ("no" >< p) argv[i++] = "-S";
- p = script_get_preference("RPC");
- if ("no" >< p) argv[i++] = "-R";
-
- p = script_get_preference("Parallel tasks"); p = int(p);
- if (p > 0) { argv[i++] = '-c'; argv[i++] = p; }
- p = script_get_preference("Connection retries"); p = int(p);
- if (p > 0) { argv[i++] = '-C'; argv[i++] = p; }
- p = script_get_preference("Connection timeout"); p = int(p);
- if (p > 0) { argv[i++] = '-T'; argv[i++] = p; }
- p = script_get_preference("Read timeout"); p = int(p);
- if (p > 0) { argv[i++] = '-t'; argv[i++] = p; }
-
- argv[i++] = ip;
- pr = get_preference("port_range");
- if (! pr) pr = "1-65535";
- foreach p (split(pr, sep: ',')) argv[i++] = p;
-
- res1 = pread(cmd: "amap", argv: argv, cd: 1, nice: 5);
- res = fread(tmpnam);
- }
-
- # IP_ADDRESS:PORT:PROTOCOL:PORT_STATUS:SSL:IDENTIFICATION:PRINTABLE_BANNER:FULL_BANNER
-
- foreach line(split(res))
- {
- v = eregmatch(string: line, pattern: '^'+esc_ip+':([0-9]+):([^:]*):([a-z]+):([^:]*):([^:]*):([^:]*):(.*)$');
- if (! isnull(v) && v[3] == "open")
- {
- scanner_status(current: ++ n_ports, total: 65535 * 2);
- port = int(v[1]); ps = string(port);
- proto = v[2];
- scanner_add_port(proto: proto, port: port);
- # As amap sometimes give several results on a same port, we save
- # the outputs and remember the last one for every port
- # The arrays use a string index to save memory
- amap_ident[ps] = v[5];
- amap_proto[ps] = proto;
- amap_ssl[ps] = v[4];
- amap_print_banner[ps] = v[6];
- amap_full_banner[ps] = v[7];
-
- }
- }
- }
-
- set_kb_item(name: "Host/scanned", value: n_ports != 0);
-
- if (udp_n && n_ports)
- set_kb_item(name: "Host/udp_scanned", value: 1);
-
- scanner_status(current: 65535 * 2, total: 65535 * 2);
-
- function cvtbanner(b)
- {
- local_var i, l, x;
- l = strlen(b);
-
- if (b[0] == '0' && b[1] == 'x')
- return hex2raw(s: substr(b, 2));
-
- x = "";
- for (i = 0; i < l; i ++)
- if (b[i] != '\\')
- x += b[i];
- else
- {
- i++;
- if (b[i] == 'n') x += '\n';
- else if (b[i] == 'r') x += '\n';
- else if (b[i] == 't') x += '\t';
- else if (b[i] == 'f') x += '\f';
- else if (b[i] == 'v') x += '\v';
- else if (b[i] == '\\') x += '\\';
- else display('cvtbanner: unhandled escape string \\'+b[i]+'\n');
- }
- return x;
- }
-
- if (! isnull(amap_ident))
- foreach p (keys(amap_ident))
- {
- port = int(p);
- if (amap_proto[p] == "tcp")
- {
- soc = open_sock_tcp(port);
- if (soc)
- close(soc);
- else
- security_hole(port: port, data: "Either this port is dynamically allocated
- or amap killed this service.
- If so, upgrade it!
-
- Risk : None / High\n");
- }
- id = amap_ident[p];
- if (id && id != "unidentified" && id != 'ssl')
- {
- security_note(port: port, proto: amap_proto[p], data: "Amap has identified this service as " + id);
- set_kb_item(name: "Amap/"+proto+"/"+port+"/Svc", value: id);
- }
-
- banner = cvtbanner(b: amap_print_banner[p]);
- set_kb_item(name: "Amap/"+proto+"/"+port+"/PrintableBanner", value: banner);
-
- banner = cvtbanner(b: amap_full_banner[p]);
- set_kb_item(name: "Amap/"+proto+"/"+port+"/FullBanner", value: banner);
- }
-